<?php
    // Comprueba que la alerta cuyo id se pasa como parámetro 
    // pertenezca o no al usuario logueado en la webapp.
    function pintaCoordenadas($MAP_OBJECT) {
        require('data.php');
        $con = mysql_connect($mysql_host, $mysql_user, $mysql_password);
        if (!$con) {
            die('Could not connect: ' . mysql_error());
        } else {
            mysql_select_db($mysql_database, $con);

            // Obtengo trabajadores
            $sql = "SELECT id FROM persona WHERE idClient = '" . $_SESSION['client'] . "'";
            $result = mysql_query($sql);
            
            $trabajadores = array();
            $i = 0;
            while ($row = mysql_fetch_array($result)) {
                $trabajadores[$i]['id'] = $row['id'];
                $i++;
            }

            foreach ($trabajadores as $esbirro) {
                $sql = "select * 
                    from snap as s 
                        join persona as p 
                        on s.idPers = p.id
                        where p.idClient = '" . $_SESSION['client'] . "' AND s.idPers = " . $esbirro['id'] . "
                        order by fecha desc
                        limit 1";
                $result = mysql_query($sql);

                while ($row = mysql_fetch_array($result)) {
                    $MAP_OBJECT->addMarkerByCoords($row['lon'], $row['lat'] , htmlentities($row['nombre']) , "<strong>" . htmlentities(ucfirst($row['nombre'])) . " " . htmlentities(ucfirst($row['apellidos'])) . "</strong><br>" . $row['telefono'] . "<br><small>" . date("G:i d/m/y",  strtotime( $row['fecha'] ) ) . "</small>", '/buscaesbirros/img/male.png', '/buscaesbirros/img/male.png' );
                }   
            }            
        }            
    }
?>